package com.naiterui.ehp.bs.patient.feign;

import java.io.IOException;
import java.util.Map;

import javax.validation.constraints.NotNull;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import com.naiterui.ehp.bp.bo.form.DesignFormBO;
import com.naiterui.ehp.bp.support.config.FeignConfiguration;
import com.naiterui.ehp.bp.support.exception.BusinessException;

/**
 * @author yangfuya
 * @since 2022/1/5
 */
@RequestMapping("inner")
@FeignClient(name = "apDesignFrom", url = "${ehp.domain.form}", configuration = FeignConfiguration.class)
public interface DesignFormFeignClient {

    /**
     * 上传表单文件
     * 
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping(value = "/design/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    String upload(@RequestPart(value = "file") @NotNull(message = "上传文件不能为null") MultipartFile file)
        throws BusinessException;

    /**
     * 保存草稿箱
     * 
     * @param formId
     * @param businessId
     * @param data
     * @return
     * @throws BusinessException
     */
    @PostMapping("/design/cache/save/{formId}/{businessId}")
    DesignFormBO saveCacheFromData(@PathVariable String formId, @PathVariable String businessId,
        @RequestBody Map<String, Object> data) throws BusinessException;

    /**
     * 获取草稿箱
     * 
     * @param formId
     * @param businessId
     * @return
     * @throws BusinessException
     */
    @PostMapping("/design/cache/get/{formId}/{businessId}")
    Map<String, Object> getCacheFromData(@PathVariable String formId, @PathVariable String businessId)
        throws BusinessException;

    /**
     * 保存表单数据
     * 
     * @param formId
     * @param businessId
     * @param data
     * @return
     * @throws BusinessException
     */
    @PostMapping("/design/{formId}/{businessId}")
    DesignFormBO saveData(@PathVariable String formId, @PathVariable String businessId,
        @RequestBody Map<String, Object> data) throws BusinessException;
}
